<template>
    <div class="todo-list">
        <h2>Todo List</h2>
        <input v-model="newtodo" placeholder="Add a new todo">
        <button @click="addtodo">Add</button>

        <ul>
            <li @click="deltodo(index)" v-for="(item, index) in todolist" :key="index">
                {{ item }}
            </li>
        </ul>
    </div>
</template>

<script setup lang='ts'>
import { reactive, ref } from "vue";

const newtodo = ref()

const todolist = reactive(
    ["Sample Todo 1", "Sample Todo 2", "Sample Todo 3", "Sample Todo 4"]
)

function addtodo() { todolist.push(newtodo.value) }
function deltodo(index:number) { todolist.splice(index,1)}
</script>

<style scoped>
.todo-list {
    text-align: center;
}

input {
    padding: 5px;
    margin-right: 10px;
}

button {
    padding: 5px;
    background-color: #2196f3;
    color: white;
    border: none;
    cursor: pointer;
}

button:hover {
    background-color: #0b7dda;
}

ul {
    list-style: none;
    padding: 0;
}

li {
    cursor: pointer;
    padding: 10px;
    margin: 5px 0;
    background-color: #f1f1f1;
}

li:hover {
    background-color: #ddd;
}
</style>